<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="会员名称">
                <a-input allow-clear placeholder="请输入店铺名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="购卡时间">
                <a-range-picker
                  format="YYYY-MM-DD HH:mm"
                  valueFormat="YYYY-MM-DD HH:mm"
                  :placeholder="['开始时间', '结束时间']"
                  v-model="queryTime"
                  @change="changeTime"
                />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false" class="card_style_re">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.search_type" @change="getList">
          <a-radio-button value="0"> 全部 </a-radio-button>
          <a-radio-button value="1"> 使用中 </a-radio-button>
          <a-radio-button value="2"> 已失效 </a-radio-button>
        </a-radio-group>
      </div>
      <a-table
        :rowKey="
          (r, i) => {
            return r.id
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.avatar" alt="" />
            </div>
            <div class="info">
              <span>{{ record.name }}</span>
              <span>{{ record.mobile }}</span>
            </div>
          </div>
        </div>
        <span slot="pay_time" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <span slot="end_time" slot-scope="text">
          {{ text != 9999999999 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '永久有效' }}
        </span>
        <span slot="pay_type" slot-scope="text">
          {{ text == 1 ? '微信' : '支付宝' }}
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { vipBuyRecord } from '@/api/saas/marketing'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '会员姓名',
    dataIndex: 'userName',
  },
  {
    title: '会员卡名称',
    dataIndex: 'cartName',
  },
  {
    title: '实付金额',
    dataIndex: 'pay_price',
    sorter: (a, b) => a.pay_price - b.pay_price,
  },
  {
    title: '付款方式',
    dataIndex: 'pay_type',
    scopedSlots: {
      customRender: 'pay_type',
    },
  },
  {
    title: '有效期',
    dataIndex: 'end_time',
    scopedSlots: {
      customRender: 'end_time',
    },
    sorter: (a, b) => a.end_time - b.end_time,
  },
  {
    title: '类型',
    dataIndex: 'alias_name',
  },
  {
    title: '购卡时间',
    dataIndex: 'pay_time',
    scopedSlots: {
      customRender: 'pay_time',
    },
    sorter: (a, b) => a.pay_time - b.pay_time,
  }
]

export default {
  components: {},
  data() {
    return {
      // 搜索参数
      queryParam: {
        page: 1,
        name: '',
        search_type: '0',
        start_time: '',
        end_time: '',
      },
      columns,
      list: [],
      btnLoading: false,
      queryTime: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 分页请求
    tablePageChange(e) {
      this.queryParam.page = e
      this.getList()
    },
    // 获取数据
    async getList() {
      const hide = this.$message.loading('加载中...', 1000)
      const res = await vipBuyRecord(this.queryParam)
      if (res.code == 0) {
        this.list = res.data.list
        this.totalCount = res.data.totalCount
      }
      hide()
    },
    // 切换筛选时间
    changeTime(e) {
      if (e.length) {
        this.queryParam.start_time = e[0]
        this.queryParam.end_time = e[1]
      } else {
        this.queryParam.start_time = ''
        this.queryParam.end_time = ''
      }
    },
  },
}
</script>
<style lang="less" scoped>
.tip {
  line-height: normal;
  margin-bottom: 0;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.pic {
  width: 48px;
  min-width: 48px;
  height: 48px;
  border-radius: 4px;
}
.status {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
  }
  .close {
    background-color: #ff4400;
  }
  .disabled {
    background-color: #ccc;
  }
  .open {
    background-color: #65c817;
  }
}
</style>
